package com.cskaoyan.service;

import com.cskaoyan.bean.adminLog.Log;
import com.cskaoyan.bean.adminLog.LogExample;
import com.cskaoyan.bean.adminLog.LogListVO;
import com.cskaoyan.mapper.LogMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class AdminLogServiceImpl implements AdminLogService {

    @Autowired
    LogMapper logMapper;

    /**
     * 返回全部日志信息
     */
    @Override
    public LogListVO list(Integer page, Integer limit, String name, String sort, String order) {
        PageHelper.startPage(page,limit);
        LogExample logExample = new LogExample();
        LogExample.Criteria criteria = logExample.createCriteria();
        if (!StringUtils.isEmpty(name)) {
            criteria.andAdminLike("%" + name + "%");
        }
        logExample.setOrderByClause(sort + " " + order);
        List<Log> logs = logMapper.selectByExample(logExample);
        PageInfo pageInfo = new PageInfo(logs);
        long total = pageInfo.getTotal();
        LogListVO logListVO = new LogListVO();
        logListVO.setItems(logs);
        logListVO.setTotal(total);
        return logListVO;
    }

}
